package com.org.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.org.common.MyServeList;
import com.org.pojo.Serve;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * ClassName: ServeMapper
 * Package: com.org.mapper
 * Description:
 *
 * @Author Origin
 * @Create 2024/2/6 13:52
 * @Version 1.0
 */

@Mapper
public interface ServeMapper extends BaseMapper<Serve> {

    @Insert("insert into serve(`title`, `content`, img01, img02, img03, img04, user_type, create_id, community_id, duration, type, " +
            " num_people, num_join, start_time, end_time, state, create_time, update_time, location, address) values(#{title}, #{content}, #{img01}, " +
            "#{img02}, #{img03}, #{img04}, #{userType}, #{createId}, #{communityId}, #{duration}, #{type}, #{numPeople}, #{numJoin}, #{startTime}," +
            " #{endTime}, #{state}, now(), now(), #{location}, #{address})")
    void add(Serve serve);


//    List<MyServeList> myServeList(String title, String type, String state, Integer userType, Integer id);

    @Update("update serve set title=#{title}, content=#{content}, img01=#{img01}, img02=#{img02}, img03=#{img03}, img04=#{img04}" +
            ", community_id=#{communityId}, duration=#{duration}, type=#{type}, num_people=#{numPeople}, start_time=#{startTime}, " +
            "end_time=#{endTime}, update_time=#{updateTime} , location=#{location}, address=#{address} where id=#{id}")
    void update(Serve serve);

    @Select("select * from serve where id = #{id}")
    Serve findById(Integer id);


    @Update("update serve set state=#{state}, update_time=now() where id=#{id}")
    void updateState(Integer id, String state);

    @Update("update serve set num_join = num_join + 1 , update_time=now() where id=#{serveId}")
    void addJoinPeople(Integer serveId);

    @Update("update serve set num_join = num_join - 1 , update_time=now() where id=#{serveId}")
    void reduceJoinPeople(Integer serveId);


    @Update("update serve set timecoins=#{json}, update_time=now() where id=#{id}")
    void updateTimecoins(String json, Integer id);
}
